package com.googlecode.bpmcenter.controller;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import org.activiti.engine.FormService;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.task.Task;

import com.googlecode.bpmcenter.service.ProcessService;
import com.googlecode.bpmcenter.util.SecurityUtil;

@ManagedBean(name = "inboxController")
@SessionScoped
public class InboxController implements Serializable {

	private static final long serialVersionUID = 1L;

	@ManagedProperty(value = "#{processService}")
	private ProcessService processService;
	
	@ManagedProperty(value = "#{formService}")
	private FormService formService;
	
	private Task currentTask;

	public ProcessService getProcessService() {
		return processService;
	}

	public void setProcessService(ProcessService processService) {
		this.processService = processService;
	}
	
	public FormService getFormService() {
  	return formService;
  }

	public void setFormService(FormService formService) {
  	this.formService = formService;
  }

	public List<Task> getPersonalTaskList() {
		return getProcessService().getPersonalTaskList();
	}

	public String getCurrentUserName() {
		return SecurityUtil.getCurrentUsername();
	}
	
	public String viewTask(String taskId){
		
		Task task = getProcessService().findTaskById(taskId);
		setCurrentTask(task);
		
		getProcessService().startTask(taskId);
		TaskFormData taskFormData = formService.getTaskFormData(taskId);
		String formKey = taskFormData.getFormKey();
		
		return formKey;
	}

	public Task getCurrentTask() {
  	return currentTask;
  }

	public void setCurrentTask(Task currentTask) {
  	this.currentTask = currentTask;
  }



}